/*
 * $Id: QEContestCategory.m 34 2009-04-21 20:24:55Z jon@bway.net $
 * Sleeper
 *
 * Created by Jon Gordon on 3/18/08
 * Copyright Jon Gordon.  All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining 
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to 
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#import "QEContestCategory.h"


@interface QEContestCategory (private)
- (void)setDesignation:(NSString *)newDesignation;
- (void)setCategoryDescription:(NSString *)newCategoryDescription;
@end


@implementation QEContestCategory
- (id)init
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [self initWithDesignation:nil categoryDescription:nil];
} // init


- (id)initWithDesignation:(NSString *)newDesignation categoryDescription:(NSString *)newCategoryDescription
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    self = [super init];
    if (nil != self) {
        [self setDesignation:newDesignation];
        [self setCategoryDescription:newCategoryDescription];
    } // if
    return self;
} // initWithDesignation:categoryDescription:


- (NSString *)designation
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[designation retain] autorelease];
} // designation

- (NSString *)categoryDescription
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[categoryDescription retain] autorelease];
} // categoryDescription

- (NSString *)description
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [NSString stringWithFormat:@"%@ - %@",
            [self designation],
            [self categoryDescription]];
} // description


- (void)dealloc
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    [designation release];
    [categoryDescription release];
    
    [super dealloc];
} // dealloc

- (id)copyWithZone:(NSZone *)zone
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    QEContestCategory *newData = [[[self class] allocWithZone:zone]
                                  initWithDesignation:[self designation]
                                  categoryDescription:[self categoryDescription]];
    return newData;
} // copyWithZone:

- (unsigned int)hash
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    static const unsigned int HASH_BASE = 17;
    static const unsigned int HASH_FACTOR = 37;
    
    unsigned int result = HASH_BASE;
    result = (result * HASH_FACTOR) + [[self designation] hash];
    result = (result * HASH_FACTOR) + [[self categoryDescription] hash];
    
    return result;
} // hash

- (BOOL)isEqual:(id)anObject
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return ((self == anObject) ||
            ([[self designation] isEqual:[anObject designation]] &&
             [[self categoryDescription] isEqual:[anObject categoryDescription]]));
} // isEqual:
@end


@implementation QEContestCategory (private)
- (void)setDesignation:(NSString *)newDesignation
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (designation != newDesignation) {
        [designation release];
        designation = [newDesignation copy];
    } // if
} // setDesignation:

- (void)setCategoryDescription:(NSString *)newCategoryDescription
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (categoryDescription != newCategoryDescription) {
        [categoryDescription release];
        categoryDescription = [newCategoryDescription copy];
    } // if
} // setCategoryDescription:
@end
